﻿package com.tudou.home.view
{
    import com.tudou.cookie.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.newskin.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.home.newskin.model.*;
    import com.tudou.newPlayer.*;
    import com.tudou.track.*;
    import com.tudou.v2.*;
    import flash.display.*;
    import flash.events.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.mediator.*;

    public class SkinMediator extends Mediator implements IMediator
    {
        private var skinBox:Sprite;
        public var percent:Number = 0;
        private var skin:ISkin;
        private var stage:Stage;
        public static const NAME:String = "SkinMediator";

        public function SkinMediator(param1:Sprite)
        {
            super(NAME);
            skinBox = param1;
            stage = skinBox.stage;
            skin = new HomeNewSkin();
            PlayerConsts.setNormalStageWidthHeight(stage.stageWidth, stage.stageHeight);
            goTransformSkin();
            skinBox.addChild(skin.getSkin());
            initListeners();
            return;
        }// end function

        public function setSkipHeadTailValue(param1:Number, param2:Number) : void
        {
            skin.setSkipHeadTailValue(param1, param2);
            return;
        }// end function

        public function goTransformSkin() : void
        {
            var _loc_1:uint = 0;
            var _loc_2:uint = 0;
            if (isFullScreen)
            {
                _loc_1 = PlayerConsts.FULLSCREEN_RECT.width;
                _loc_2 = PlayerConsts.FULLSCREEN_RECT.height;
            }
            else
            {
                _loc_1 = PlayerConsts.SKIN_WIDTH;
                _loc_2 = PlayerConsts.SKIN_HEIGTH;
            }
            skin.goTransform(_loc_1, _loc_2, isFullScreen);
            return;
        }// end function

        public function setExand(param1:Boolean) : void
        {
            skin.setExpand(param1);
            return;
        }// end function

        public function setPlaylistSingleContinue(param1:Boolean) : void
        {
            skin.setPlaylistSingleContinue(param1);
            return;
        }// end function

        public function setCopyright(param1:Boolean) : void
        {
            skin.setCopyright(param1);
            return;
        }// end function

        public function startTransFinishTimeout() : void
        {
            skin.startTransFinishTimeout();
            return;
        }// end function

        public function removeAdOverlay() : void
        {
            skin.removeAdOverlay();
            return;
        }// end function

        public function showPreview() : void
        {
            skin.showPreview();
            return;
        }// end function

        public function setRelativeList(param1:Array) : void
        {
            skin.setRelativeList(param1);
            return;
        }// end function

        private function initListeners() : void
        {
            stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullscreenHlr);
            stage.addEventListener(Event.RESIZE, resizeHlr);
            skin.addEventListener(SkinEvent.PAUSE, skinEventHandler);
            skin.addEventListener(SkinEvent.PLAY, skinEventHandler);
            skin.addEventListener(SkinEvent.TOGGLE_PAUSE, skinEventHandler);
            skin.addEventListener(SkinEvent.REPLAY, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_BRIGHTNESS, skinEventHandler);
            skin.addEventListener(SkinEvent.END_SET_BRIGHTNESS, skinEventHandler);
            skin.addEventListener(SkinEvent.MUTE, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_VOLUME, skinEventHandler);
            skin.addEventListener(SkinEvent.END_SET_VOLUME, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_FULLSCREEN, skinEventHandler);
            skin.addEventListener(SkinEvent.ENTER_FULLSCREEN, skinEventHandler);
            skin.addEventListener(SkinEvent.EXIT_FULLSCREEN, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_EXPAND, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_VIDEO_SCALE, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_ORIGINAL_VIDEO_SCALE, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_VIDEO_SIZE, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_CLOCKWISE, skinEventHandler);
            skin.addEventListener(SkinEvent.PREVIEW, skinEventHandler);
            skin.addEventListener(SkinEvent.CLOSE_PREVIEW, skinEventHandler);
            skin.addEventListener(SkinEvent.SAVE_RATE_SETTING, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_RATE, skinEventHandler);
            skin.addEventListener(SkinEvent.SEEKING, skinEventHandler);
            skin.addEventListener(SkinEvent.START_SEEK, skinEventHandler);
            skin.addEventListener(SkinEvent.END_SEEK, skinEventHandler);
            skin.addEventListener(SkinEvent.THIS_INDEX, skinEventHandler);
            skin.addEventListener(SkinEvent.BUTTON_LOG, skinEventHandler);
            skin.addEventListener(SkinEvent.OVER_SKIP_MARKER, skinEventHandler);
            skin.addEventListener(SkinEvent.SAVE_SKIP_SETTING, skinEventHandler);
            skin.addEventListener(SkinEvent.SINGLE_NEXT_INDEX, skinEventHandler);
            skin.addEventListener(SkinEvent.SINGLE_THIS_INDEX, skinEventHandler);
            skin.addEventListener(SkinEvent.SET_PLAYLIST_SINGLE_CONTINUE, skinEventHandler);
            return;
        }// end function

        private function init() : void
        {
            return;
        }// end function

        public function setVideoScale(param1:Number) : void
        {
            skin.setVideoScale(param1);
            return;
        }// end function

        public function set showTransFinished(param1:Boolean) : void
        {
            skin.showTransFinished = param1;
            return;
        }// end function

        public function setPlayState(param1:int) : void
        {
            if (param1 < VideoStatus.READY)
            {
                skin.loading();
            }
            else if (param1 == VideoStatus.READY)
            {
                skin.ready();
            }
            else if (param1 == VideoStatus.PLAYING)
            {
                skin.playing();
            }
            else if (param1 == VideoStatus.PAUSED)
            {
                skin.paused();
            }
            else if (param1 == VideoStatus.COMPLETED)
            {
                complete();
            }
            else if (param1 == VideoStatus.BUFFERING)
            {
                skin.buffering();
            }
            return;
        }// end function

        public function setRateSetting(param1:RateSettingData) : void
        {
            skin.setRateSetting(param1);
            return;
        }// end function

        public function setIndex(param1:int) : void
        {
            skin.setIndex(param1);
            return;
        }// end function

        private function resizeHlr(event:Event) : void
        {
            trace("舞台大小变了！", isFullScreen, stage.stageWidth, stage.stageHeight);
            if (isFullScreen)
            {
                PlayerConsts.setFullStageWidthHeight(stage.stageWidth, stage.stageHeight);
                skin.enterFullscreen();
                sendNotification(ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE);
            }
            else
            {
                if (stage.stageWidth <= 0 || stage.stageHeight <= 0)
                {
                    return;
                }
                PlayerConsts.setNormalStageWidthHeight(stage.stageWidth, stage.stageHeight);
                skin.exitFullscreen();
                sendNotification(ViewCommandSet.NORMALSCREEN_RESIZE);
            }
            return;
        }// end function

        public function setMute(param1:Boolean) : void
        {
            skin.setMute(param1);
            return;
        }// end function

        public function setSkipSeting(param1:SkipSettingData) : void
        {
            skin.setSkipSeting(param1);
            return;
        }// end function

        public function setMaxRate(param1:int, param2:Boolean) : void
        {
            skin.setMaxRate(param1, param2);
            return;
        }// end function

        public function setVolume(param1:Number) : void
        {
            skin.setVolume(param1);
            return;
        }// end function

        public function get isFullScreen() : Boolean
        {
            return skinBox.stage.displayState == StageDisplayState.FULL_SCREEN;
        }// end function

        public function stopTransFinishTimeout() : void
        {
            skin.stopTransFinishTimeout();
            return;
        }// end function

        public function hasSkipHeadTail(param1:Boolean) : void
        {
            skin.hasSkipHeadTail(param1);
            return;
        }// end function

        public function showPlayComplete() : void
        {
            skin.showComplete();
            return;
        }// end function

        public function changeVideo(param1:DisplayObject) : void
        {
            skin.addVideo(param1);
            return;
        }// end function

        public function setPreviewer(param1:DisplayObject) : void
        {
            skin.setPreviewer(param1);
            return;
        }// end function

        public function setBaseVideoInfo(param1:IBaseVideoInfo) : void
        {
            skin.setBaseVideoInfo(param1);
            return;
        }// end function

        public function complete() : void
        {
            skin.completed();
            return;
        }// end function

        public function setOriginalWidthHeight(param1:int, param2:int) : void
        {
            skin.setOriginalWidthHeight(param1, param2);
            return;
        }// end function

        public function setRateType(param1:int) : void
        {
            skin.setRate(param1);
            return;
        }// end function

        private function setFullscreen() : void
        {
            try
            {
                if (isFullScreen)
                {
                    if (PlayerConsts.HAS_HARD_WORK)
                    {
                        stage.fullScreenSourceRect = null;
                    }
                    stage.displayState = StageDisplayState.NORMAL;
                }
                else
                {
                    if (PlayerConsts.HAS_HARD_WORK)
                    {
                        stage.fullScreenSourceRect = PlayerConsts.FULLSCREEN_RECT;
                    }
                    stage.displayState = StageDisplayState.FULL_SCREEN;
                }
            }
            catch (e:Error)
            {
                trace("Failed to fullscreen!", e);
            }
            return;
        }// end function

        public function addFloatAd(param1:DisplayObject) : void
        {
            skin.setAdFloat(param1);
            return;
        }// end function

        public function setOriginalVideoScale(param1:Boolean) : void
        {
            skin.setOriginalVideoScale(param1);
            return;
        }// end function

        public function showSettingedSkipTip() : void
        {
            skin.showSettingedSkipTip();
            return;
        }// end function

        public function setUpdate(param1:Object) : void
        {
            skin.setPlayed(param1.playTimePos);
            skin.setLoaded(param1.loadTimePos);
            skin.setPlayTime(param1.playTime);
            skin.setTotalTime(param1.totalTime);
            return;
        }// end function

        public function setAdPause(param1:DisplayObject) : void
        {
            skin.setAdPause(param1);
            return;
        }// end function

        public function setBrightness(param1:Number) : void
        {
            skin.setBrightness(param1);
            return;
        }// end function

        private function fullscreenHlr(event:FullScreenEvent) : void
        {
            trace("全屏事件：", event.fullScreen, stage.stageWidth, stage.stageHeight);
            if (event.fullScreen)
            {
                AOPTracker.getInst().addNodeLog(NodeLog.PLAYER_FULL_SCREEN);
            }
            else
            {
                AOPTracker.getInst().addNodeLog(NodeLog.PLAYER_NORAML_SCREEN);
                sendNotification(ViewCommandSet.REAL_EXIT_FULLCREEN);
            }
            return;
        }// end function

        public function setAdVideo(param1:DisplayObject) : void
        {
            skin.setAdVideo(param1);
            return;
        }// end function

        public function setVideoSize(param1:int) : void
        {
            skin.setVideoSize(param1);
            return;
        }// end function

        public function setOriginalRate(param1:Number) : void
        {
            skin.setOriginalRate(param1);
            return;
        }// end function

        override public function listNotificationInterests() : Array
        {
            return [V2CommandSet.INFO_ERROR, V2CommandSet.INFO_LOADED, PlayerCommandSet.SHOW_FAILURE, PlayerCommandSet.SHOW_BUFFER, PageCommandSet.SHARE_DATA_LOADED, PlayerCommandSet.SHOW_SKIN_TIP];
        }// end function

        public function setAdOverlay(param1:DisplayObject) : void
        {
            skin.setAdOverlay(param1);
            return;
        }// end function

        override public function handleNotification(param1:INotification) : void
        {
            var _loc_2:* = undefined;
            var _loc_3:VideoInfo = null;
            var _loc_4:Boolean = false;
            _loc_2 = param1.getBody();
            switch(param1.getName())
            {
                case V2CommandSet.INFO_LOADED:
                {
                    _loc_3 = _loc_2 as VideoInfo;
                    if (_loc_3)
                    {
                        skin.isAudio(_loc_3.isAudio);
                    }
                    break;
                }
                case V2CommandSet.INFO_ERROR:
                {
                    if (int(_loc_2) != 9)
                    {
                        skin.showError(int(_loc_2));
                    }
                    break;
                }
                case PlayerCommandSet.SHOW_FAILURE:
                {
                    _loc_4 = Boolean(_loc_2);
                    skin.showFastTip(_loc_4);
                    break;
                }
                case PlayerCommandSet.SHOW_BUFFER:
                {
                    skin.showTip(0);
                    break;
                }
                case PageCommandSet.SHARE_DATA_LOADED:
                {
                    skin.setShareItemList(_loc_2);
                    break;
                }
                case PlayerCommandSet.SHOW_SKIN_TIP:
                {
                    skin.showTip(int(_loc_2));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function skinEventHandler(event:SkinEvent) : void
        {
            var _loc_2:* = event.data;
            switch(event.type)
            {
                case SkinEvent.END_SET_VOLUME:
                {
                    sendNotification(PlayerCommandSet.END_SET_VOLUME, _loc_2);
                    break;
                }
                case SkinEvent.MUTE:
                {
                    sendNotification(PlayerCommandSet.MUTE, _loc_2);
                    break;
                }
                case SkinEvent.SET_VOLUME:
                {
                    sendNotification(PlayerCommandSet.SET_VOLUME, _loc_2);
                    break;
                }
                case SkinEvent.PAUSE:
                {
                    sendNotification(PlayerCommandSet.PAUSE);
                    break;
                }
                case SkinEvent.PLAY:
                {
                    sendNotification(PlayerCommandSet.PLAY);
                    break;
                }
                case SkinEvent.START_SEEK:
                case SkinEvent.SEEKING:
                case SkinEvent.END_SEEK:
                {
                    sendNotification(PlayerCommandSet.SEEK, {seekPoint:event.data, isDraging:skin.isDragging()});
                    break;
                }
                case SkinEvent.SET_FULLSCREEN:
                {
                    setFullscreen();
                    break;
                }
                case SkinEvent.ENTER_FULLSCREEN:
                {
                    if (!isFullScreen)
                    {
                        setFullscreen();
                    }
                    break;
                }
                case SkinEvent.EXIT_FULLSCREEN:
                {
                    if (isFullScreen)
                    {
                        setFullscreen();
                    }
                    break;
                }
                case SkinEvent.SET_EXPAND:
                {
                    sendNotification(ViewCommandSet.EXPAND_STAGE, _loc_2, NAME);
                    break;
                }
                case SkinEvent.TOGGLE_PAUSE:
                {
                    sendNotification(PlayerCommandSet.TOGGLE_PAUSE, _loc_2);
                    break;
                }
                case SkinEvent.SET_RATE:
                {
                    sendNotification(PlayerCommandSet.CHANGE_RATE_TYPE, _loc_2, SkinMediator.NAME);
                    break;
                }
                case SkinEvent.SAVE_RATE_SETTING:
                {
                    sendNotification(PlayerCommandSet.SET_COOKIE_RATE, _loc_2);
                    break;
                }
                case SkinEvent.REPLAY:
                {
                    sendNotification(PlayerCommandSet.REPLAY);
                    break;
                }
                case SkinEvent.THIS_INDEX:
                {
                    sendNotification(PlayListCommandSet.THIS_INDEX, _loc_2);
                    break;
                }
                case SkinEvent.SET_VIDEO_SIZE:
                {
                    sendNotification(PlayerCommandSet.SET_VIDEO_SIZE, _loc_2);
                    break;
                }
                case SkinEvent.SET_CLOCKWISE:
                {
                    sendNotification(PlayerCommandSet.SET_CLOCK_WISE, _loc_2);
                    break;
                }
                case SkinEvent.SET_BRIGHTNESS:
                {
                    sendNotification(PlayerCommandSet.SET_BRIGHTNESS, _loc_2);
                    break;
                }
                case SkinEvent.END_SET_BRIGHTNESS:
                {
                    sendNotification(PlayerCommandSet.END_SET_BRIGHTNESS, _loc_2);
                    break;
                }
                case SkinEvent.SET_VIDEO_SCALE:
                {
                    sendNotification(PlayerCommandSet.SET_VIDEO_SCALE, _loc_2);
                    break;
                }
                case SkinEvent.SET_ORIGINAL_VIDEO_SCALE:
                {
                    sendNotification(PlayerCommandSet.SET_ORIGINAL_VIDEO_SCALE, _loc_2);
                    break;
                }
                case SkinEvent.PREVIEW:
                {
                    sendNotification(PlayerCommandSet.PREVIEW, _loc_2);
                    break;
                }
                case SkinEvent.CLOSE_PREVIEW:
                {
                    sendNotification(PlayerCommandSet.CLOSE_PREVIEW);
                    break;
                }
                case SkinEvent.BUTTON_LOG:
                {
                    sendNotification(PlayerCommandSet.BUTTON_LOG, _loc_2);
                    break;
                }
                case SkinEvent.OVER_SKIP_MARKER:
                {
                    skin.showSettingSkipTip();
                    break;
                }
                case SkinEvent.SAVE_SKIP_SETTING:
                {
                    sendNotification(PlayerCommandSet.SET_COOKIE_SKIP, _loc_2);
                    break;
                }
                case SkinEvent.SINGLE_NEXT_INDEX:
                {
                    sendNotification(PlayListSingleCommandSet.NEXT_ITEM);
                    break;
                }
                case SkinEvent.SINGLE_THIS_INDEX:
                {
                    sendNotification(PlayListSingleCommandSet.THIS_INDEX, _loc_2);
                    break;
                }
                case SkinEvent.SET_PLAYLIST_SINGLE_CONTINUE:
                {
                    sendNotification(PlayListSingleCommandSet.SET_COOKIE_PLAYLIST_SINGLE_CONTINUE, _loc_2);
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        public function removeAdPause() : void
        {
            skin.removeAdPause();
            return;
        }// end function

        public function setPlayList(param1:Array) : void
        {
            skin.setPlayList(param1);
            return;
        }// end function

        public function hidePlayComplete() : void
        {
            skin.hideComplete();
            return;
        }// end function

        public function setPlayerEvent(param1:String) : void
        {
            if (param1 == PlayerEvent.STREAM_BUFFER_FULL)
            {
                skin.bufferFull();
            }
            else if (param1 == PlayerEvent.STREAM_BUFFER_EMPTY)
            {
                skin.bufferEmpty();
            }
            return;
        }// end function

        public function addCornerAD(param1:DisplayObject) : void
        {
            skin.setAdCorner(param1);
            return;
        }// end function

        public function removeAdVideo() : void
        {
            skin.removeAdVideo();
            return;
        }// end function

    }
}
